/********************************************************************
* @Copyright: Metanergy Technology R&D Co., Ltd
* @Filename : myg0025_opamp.h
* @brief    : API file of comp module
* @Author   : AE Team
  * @version V1.0.0/2023-04-08
  * @log  V1.0.0/2023-04-08 Initial release
 ********************************************************************/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MYG0025_OPAMP_H
#define __MYG0025_OPAMP_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "myg0025.h"

/** @addtogroup OPAMP
  * @{
  */

/** @defgroup OPAMP_Exported_Types OPAMP_Exported_Types
  * @{
  */

/**
  * @brief OPAMP Init structure definition
  */
typedef struct
{
    uint32_t FunctionalMode;

    uint32_t InputNonInverting;

    uint32_t InputInverting;
} OPAMP_InitTypeDef;


/**
  * @brief OPAMP output selection enum
  */
typedef enum
{
    OPAMP_OUT0,
    OPAMP_OUT1,
    OPAMP_OUT2,
    OPAMP_OUTALL
} OPAMP_OUT_SEL_Type;
/**
  * @}
  */

/** @defgroup OPAMP_Define OPAMP_Define
  * @{
  */


/*********************************OPAMP PGA Gain***************************************************************/
#define OPAMP_PGA_GAIN_1                        ((uint32_t)0x00000000<<OPAMP_CSR_PGA_GAIN_Pos)
#define OPAMP_PGA_GAIN_2                        ((uint32_t)0x00000001<<OPAMP_CSR_PGA_GAIN_Pos)
#define OPAMP_PGA_GAIN_5                        ((uint32_t)0x00000002<<OPAMP_CSR_PGA_GAIN_Pos)
#define OPAMP_PGA_GAIN_8                        ((uint32_t)0x00000003<<OPAMP_CSR_PGA_GAIN_Pos)
#define OPAMP_PGA_GAIN_10                       ((uint32_t)0x00000004<<OPAMP_CSR_PGA_GAIN_Pos)
#define OPAMP_PGA_GAIN_14                       ((uint32_t)0x00000005<<OPAMP_CSR_PGA_GAIN_Pos)
#define OPAMP_PGA_GAIN_16                       ((uint32_t)0x00000006<<OPAMP_CSR_PGA_GAIN_Pos)
#define OPAMP_PGA_GAIN_20                       ((uint32_t)0x00000007<<OPAMP_CSR_PGA_GAIN_Pos)
#define OPAMP_PGA_GAIN_2_VM0_FILTER             ((uint32_t)0x00000011<<OPAMP_CSR_PGA_GAIN_Pos)
#define OPAMP_PGA_GAIN_5_VM0_FILTER             ((uint32_t)0x00000012<<OPAMP_CSR_PGA_GAIN_Pos)
#define OPAMP_PGA_GAIN_8_VM0_FILTER             ((uint32_t)0x00000013<<OPAMP_CSR_PGA_GAIN_Pos)
#define OPAMP_PGA_GAIN_10_VM0_FILTER            ((uint32_t)0x00000014<<OPAMP_CSR_PGA_GAIN_Pos)
#define OPAMP_PGA_GAIN_14_VM0_FILTER            ((uint32_t)0x00000015<<OPAMP_CSR_PGA_GAIN_Pos)
#define OPAMP_PGA_GAIN_16_VM0_FILTER            ((uint32_t)0x00000016<<OPAMP_CSR_PGA_GAIN_Pos)
#define OPAMP_PGA_GAIN_20_VM0_FILTER           ((uint32_t)0x00000017<<OPAMP_CSR_PGA_GAIN_Pos)
/**************************************************************************************************************/


/*********************************OPAMP Non-inverting Input****************************************************/
#define OPAMP_INPUT_NONINVERT_VP0      ((uint32_t)0x00000000<<OPAMP_CSR_VP_SEL_Pos)
#define OPAMP_INPUT_NONINVERT_VP1      ((uint32_t)0x00000001<<OPAMP_CSR_VP_SEL_Pos)
#define OPAMP_INPUT_NONINVERT_VP2      ((uint32_t)0x00000002<<OPAMP_CSR_VP_SEL_Pos)
#define OPAMP_INPUT_NONINVERT_VP3      ((uint32_t)0x00000003<<OPAMP_CSR_VP_SEL_Pos)
/**************************************************************************************************************/


/*********************************OPAMP Inverting Input********************************************************/
#define OPAMP_INPUT_INVERT_VM0        ((uint32_t)0x00000000<<OPAMP_CSR_VM_SEL_Pos)
#define OPAMP_INPUT_INVERT_VM1        ((uint32_t)0x00000001<<OPAMP_CSR_VM_SEL_Pos)
#define OPAMP_MODE_PGA                ((uint32_t)0x00000002<<OPAMP_CSR_VM_SEL_Pos)
#define OPAMP_MODE_FOLLOWER           (OPAMP_MODE_PGA)
/**************************************************************************************************************/

/*********************************OPAMP Secondary Non-inverting Input******************************************/
#define OPAMP_INPUT_NONINVERT_VP0_SEC   ((uint32_t)0x00000000<<OPAMP_CSR_VP_SEL_Pos)
#define OPAMP_INPUT_NONINVERT_VP1_SEC   ((uint32_t)0x00000001<<OPAMP_CSR_VP_SEL_Pos)
#define OPAMP_INPUT_NONINVERT_VP2_SEC   ((uint32_t)0x00000002<<OPAMP_CSR_VP_SEL_Pos)
#define OPAMP_INPUT_NONINVERT_VP3_SEC   ((uint32_t)0x00000003<<OPAMP_CSR_VP_SEL_Pos)
/**************************************************************************************************************/

/*********************************OPAMP Secondary Inverting Input**********************************************/
#define OPAMP_INPUT_INVERT_VM0_SEC      ((uint32_t)0x00000000<<OPAMP_CSR_VM_SEL_Pos)
#define OPAMP_INPUT_INVERT_VM1_SEC      ((uint32_t)0x00000001<<OPAMP_CSR_VM_SEL_Pos)
/**************************************************************************************************************/

/*********************************OPAMP Operating Mode*********************************************************/
#define OPAMP_FUNCTIONAL_MODE           ((uint32_t)0x00000000<<OPAMP_CSR_CALON_Pos)
#define OPAMP_CALIBRATION_MODE          ((uint32_t)0x00000001<<OPAMP_CSR_CALON_Pos)
/**************************************************************************************************************/

/*********************************OPAMP Trimming Mode**********************************************************/
#define OPAMP_TRIMMING_SELECT_MASK              (OPAMP_CSR_CALSEL)
#define OPAMP_TRIMMING_VALUE_MASK               (OPAMP_CSR_TRIMVOSN | OPAMP_CSR_TRIMVOSP)
#define OPAMP_TRIMMING_FACTORY                  ((uint32_t)0x00000000)
#define OPAMP_TRIMMING_USER                     (OPAMP_CSR_USER_TRIM)
#define OPAMP_TRIMMING_NMOS_VREF_90PC_VDDA      ((uint32_t)0x00000000<<OPAMP_CSR_CALSEL_Pos)
#define OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA      ((uint32_t)0x00000001<<OPAMP_CSR_CALSEL_Pos)
#define OPAMP_TRIMMING_PMOS_VREF_10PC_VDDA      ((uint32_t)0x00000002<<OPAMP_CSR_CALSEL_Pos)
#define OPAMP_TRIMMING_PMOS_VREF_5PC_VDDA       ((uint32_t)0x00000003<<OPAMP_CSR_CALSEL_Pos)
#define OPAMP_TRIMMING_NMOS                     (OPAMP_TRIMMING_NMOS_VREF_90PC_VDDA)
#define OPAMP_TRIMMING_PMOS                     (OPAMP_TRIMMING_PMOS_VREF_10PC_VDDA)
#define OPAMP_FORCE_VP_DISABLE                  ((uint32_t)0x00000000<<OPAMP_CSR_FORCE_VP_Pos)
#define OPAMP_FORCE_VP_ENABLE                   ((uint32_t)0x00000001<<OPAMP_CSR_FORCE_VP_Pos)
#define OPAMP_CALON_DISABLE                     ((uint32_t)0x00000000<<OPAMP_CSR_CALON_Pos)
#define OPAMP_CALON_ENABLE                      ((uint32_t)0x00000001<<OPAMP_CSR_CALON_Pos)
#define OPAMP_USER_TRIM_DISABLE                 ((uint32_t)0x00000000<<OPAMP_CSR_USER_TRIM_Pos)
#define OPAMP_USER_TRIM_ENABLE                  ((uint32_t)0x00000001<<OPAMP_CSR_USER_TRIM_Pos)
/**************************************************************************************************************/

/*********************************OPAMP Clock division*********************************************************/
#define OPAMP_CLKDIV1024         (OPAMP_CKSEL_DIV1024_SEL)
/**************************************************************************************************************/

#define OPAMP_Gnd_Internal       ((uint32_t)0x00000000<<OPAMP_CSR_GND_SEL_Pos)
#define OPAMP_Gnd_External       ((uint32_t)0x00000001<<OPAMP_CSR_GND_SEL_Pos)

/**
  * @}
  */

/**
  * @}
  */


void OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode);
uint32_t OPAMP_GetMode(OPAMP_TypeDef *OPAMPx);

void OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain);
uint32_t OPAMP_GetPGAGain(OPAMP_TypeDef *OPAMPx);

void OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting);
uint32_t OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx);

void OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting);
uint32_t OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx);

void OPAMP_SetInputNonInvertingSecondary(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting);
uint32_t OPAMP_GetInputNonInvertingSecondary(OPAMP_TypeDef *OPAMPx);

void OPAMP_SetInputInvertingSecondary(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting);
uint32_t OPAMP_GetInputInvertingSecondary(OPAMP_TypeDef *OPAMPx);

void OPAMP_SetTrimmingMode(OPAMP_TypeDef *OPAMPx, uint32_t TrimmingMode);
uint32_t OPAMP_GetTrimmingMode(OPAMP_TypeDef *OPAMPx);

void OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair);
uint32_t OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx);
uint32_t OPAMP_GetCalibrationOutput(OPAMP_TypeDef *OPAMPx);

void OPAMP_SetTrimmingValue(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair, uint32_t TrimmingValue);
uint32_t OPAMP_GetTrimmingValue(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair);

void OPAMP_Enable(OPAMP_TypeDef *OPAMPx);
void OPAMP_Disable(OPAMP_TypeDef *OPAMPx);
uint32_t OPAMP_IsEnabled(OPAMP_TypeDef *OPAMPx);

void OPAMP_SetForceVPState(OPAMP_TypeDef *OPAMPx, uint32_t ForceVPState);
uint32_t OPAMP_GetForceVPState(OPAMP_TypeDef *OPAMPx);

void OPAMP_SetCALONState(OPAMP_TypeDef *OPAMPx, uint32_t CALONState);
uint32_t OPAMP_GetCALONState(OPAMP_TypeDef *OPAMPx);

void OPAMP_SetUserTrimState(OPAMP_TypeDef *OPAMPx, uint32_t UserTrimState);
uint32_t OPAMP_GetUserTrimState(OPAMP_TypeDef *OPAMPx);

void OPAMP_SetTRIMOFFSETN(OPAMP_TypeDef *OPAMPx, uint32_t TRIMOFFSETValue);
uint32_t OPAMP_GetTRIMOFFSETN(OPAMP_TypeDef *OPAMPx);
void OPAMP_SetTRIMOFFSETP(OPAMP_TypeDef *OPAMPx, uint32_t TRIMOFFSETValue);
uint32_t OPAMP_GetTRIMOFFSETP(OPAMP_TypeDef *OPAMPx);

void OPAMP_Lock(OPAMP_TypeDef *OPAMPx);
uint32_t OPAMP_IsLocked(OPAMP_TypeDef *OPAMPx);

void OPAMP_DeInit(void);
ErrorStatus OPAMP_Init(OPAMP_TypeDef *OPAMPx, OPAMP_InitTypeDef *OPAMP_InitStruct);

void OPAMP_SetOutput(OPAMP_TypeDef *OPAMPx, OPAMP_OUT_SEL_Type OpaOutput, FunctionalState NewState);

void OPAMP_SetHardwareTrim(OPAMP_TypeDef *OPAMPx);
uint32_t OPAMP_GetHardwareTrim(OPAMP_TypeDef *OPAMPx);

void OPAMP_HWTrimClk(void);
void OPAMP_GND_Sel(OPAMP_TypeDef *OPAMPx, uint32_t OPAMP_GndSel);
uint32_t OPAMP_GetPGAGND_Sel(OPAMP_TypeDef *OPAMPx);

#ifdef __cplusplus
}
#endif

#endif /* __MYG0025_OPAMP_H */

/***************************** (C) COPYRIGHT Metanergy  *******************************/
